<?php
/*
	提现
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
*/
defined('BY_JYA') or exit('error');
global $_RQ;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'get';
cfc('core')->checklogin();
$credit_types=credit_types(true);
if($_RQ['op']=='get'){
    $return['jifenset']=$this->plugin_setting('jifenbasic');
	$up_type=$tixianset['up_type']?:3;
	if($_SESSION['onemerchid']){
		$member=model('jy_merch/member')->getdetail($_SESSION['onemerchid'],$_SESSION['uid']);
	}else{
		$member=pdo_get('core_members',array('id'=>$_SESSION['uid']));
	}
    $bmember=$this->get('member',array('mid'=>$_SESSION['uid']),array('mid','bfee'));
    $member=array_merge($bmember,$member);
	$tinum=intval($return['allmoney']/$tixianset['man_fee']);
	$return['man_fee']=$tixianset['man_fee'];
    $return['member']=$member;
    $return['params']['type']=$_RQ['type']?:3;
	if($return['params']['type']==10){
        $return['allmoney']=$member['bfee'];
        $return['typetitle']='银币';
    }else{
        $return['allmoney']=$member['credit'.$return['params']['type']];
        $return['typetitle']=$credit_types[$return['params']['type']];
    }
    $return['sf_typetitle']=$credit_types[$this->setting['sf_btype']];
	if($return['params']['type']==3){
		$tips='购买商品，参与分享都可以获得《'.$return['typetitle'].'》哦！';
	}elseif($return['params']['type']==4){
		$tips='可以充值获得《'.$return['typetitle'].'》哦！';
	}if($return['params']['type']==6){
		$tips='签到，直推人参与拼团，购买指定商品，都可以获得《'.$return['typetitle'].'》哦！';
	}
	$return['tips']=$tips;
	$return['is_open']=$tixianset['is_open'];
	$return['open_upbaofee']=$tixianset['open_upbaofee'];
	if($this->setting['sfall_fee']>0 && $return['params']['type']==1){
		$return['sfall_fee']=intval($return['allmoney']*$this->setting['sfall_fee'])/100;
	}
	if(($return['allmoney']>=$this->setting['b1_manfee'] || !$this->setting['b1_manfee']) && $return['params']['type']==1){
		$return['cansf']=1;
	}
	$pay=uni_setting('pay');
	$return['iszhuan']=$pay['credit'.$return['params']['type'].'_zhuan'];
	$return['post']=array();
	set_html('title','我的'.$return['typetitle']);
	exi($return);
}
if($_RQ['op']=='fenlist'){
	$pindex = max(1, intval($_RQ['page']));
	$psize = 15;
	$params=array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'type'=>array(12,13));
	if($_RQ['type']){
		$params['type']=intval($_RQ['type']);
	}
    $orderby='createtime desc';
	$total='';
	$list=pdo_getslice('jy_gufee_commission',$params,array($pindex,$psize),$total,'','','id desc');
	if($list){
		foreach($list as &$item){
            $item['fee']=$item['jifen'];
			$item['createtime']=date('Y/m/d H:i:s',$item['createtime']);
			$item['is_addtitle']=$item['type']==12?'获得':'消费';
			$item['remark']=$this->commission_money_types[$item['type']];
		}
	}
	$return['list']=$list;
	exi($return);
}
if($_RQ['op']=='zhuan3'){
    $post=get_postdata();
    $sf_typetitle=$credit_types[$this->setting['sf_type']];
    $member=pdo_get('core_members',array('id'=>$_SESSION['uid']));
    $post['fee']=$member['credit1'];
	if($post['fee']<$this->setting['b1_manfee'] && $this->setting['b1_manfee']){
        exi('满'.$this->setting['b1_manfee'].',才能兑换！','erroe');
    }
    $endfee=$post['fee'];
    if($this->setting['sfall_fee']>0){
        $sf_fee=intval($post['fee']*$this->setting['sfall_fee'])/100;
        $endfee -=$sf_fee;
    }
    if($member['credit1']<$post['fee']){
        exi('释放额度不能大于，当前剩余额度！','erroe');
    }
    pdo_update('jy_gufee_member',array('bfee +='=>$endfee),array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']));
    model('core/member')->member_credit($_SESSION['uid'],'credit1',$post['fee'],false,'jy_gufee','释放'.$sf_typetitle);
    $new_commission=array(
        'uniacid'=>$_SESSION['uniacid'],
        'mid'=>$_SESSION['uid'],
        'money'=>0,
        'jifen'=>$endfee,
        'createtime'=>TIMESTAMP,
        'status'=>2,
        'type'=>12,
    );
    $this->insert('commission',$new_commission);
    exi('释放成功！');
}
if($_RQ['op']=='zhuan4'){
    $post=get_postdata();
    $type=$this->setting['sf_btype'];
    if(!$type){
        exi('未开启币种赠送！','erroe');
    }
    $sf_typetitle=$credit_types[$this->setting['sf_type']];
    $member=pdo_get('core_members',array('id'=>$_SESSION['uid']));
    if(!$post['fee']){
        exi('请输入转账'.$sf_typetitle.'额度！','erroe');
    }
    if(!$post['mobile']){
        exi('请输入收款人账户/手机号！','erroe');
    }
    if($member['credit'.$type]<$post['fee']){
        exi('转账额度不能大于，当前积分额度！','erroe');
    }
    $tomember=pdo_get('core_members',array('uniacid'=>$_SESSION['uniacid'],'username'=>$post['mobile']));
    $tomid=$tomember['id'];
    if(!$tomid){
        $tomember=pdo_get('core_members',array('uniacid'=>$_SESSION['uniacid'],'mobile'=>$post['mobile']));
        $tomid=$tomember['onemid']?:$tomember['id'];
    }
    if(!$tomid){
        exi('没找到收款人，转账失败！','erroe');
    }
    model('core/member')->member_credit($_SESSION['uid'],'credit'.$type,$post['fee'],false,'jy_gufee','转账给:'.$post['mobile']);
    model('core/member')->member_credit($tomid,'credit'.$type,$post['fee'],true,'jy_gufee',$member['username'].'的转账');
    exi('转账成功！');
}
if($_RQ['op']=='zhuan10'){
    $post=get_postdata();
    $sf_typetitle=$credit_types[$this->setting['sf_type']];
    $member=$this->get('member',array('mid'=>$_SESSION['uid']),array('mid','bfee'));
    if(!$post['fee']){
        exi('请输入兑换额度！','erroe');
    }
    if($post['fee']<$this->setting['b_manfee'] && $this->setting['b_manfee']){
        exi('满'.$this->setting['b_manfee'].',才能兑换！','erroe');
    }
    $endfee=$post['fee'];
    if($this->setting['sf_fee']>0){
        $sf_fee=$post['fee']*$this->setting['sf_fee']/100;
        $endfee -=$sf_fee;
    }
    if($member['bfee']<$post['fee']){
        exi('兑换额度不能大于，当前剩余额度！','erroe');
    }
    pdo_update('jy_gufee_member',array('bfee -='=>$post['fee']),array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']));
    model('core/member')->member_credit($_SESSION['uid'],'credit3',$endfee,add,'jy_gufee','银币兑换');
    $new_commission=array(
        'uniacid'=>$_SESSION['uniacid'],
        'mid'=>$_SESSION['uid'],
        'money'=>0,
        'jifen'=>$post['fee'],
        'createtime'=>TIMESTAMP,
        'status'=>2,
        'type'=>13,
    );
    $this->insert('commission',$new_commission);
    exi('兑换成功！');
}